package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.entity.WorkModeReply;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeWorkMode implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248050395985,V4,MODE,098745,m2,400,145306,A,2250.2214,N,11391.6105,E,0.18,281,030621,FDFFFFFF
        //解密
        String[] split = parseCommand(originalData);
        String imei=split[1];
        String commandNumber = split[4];//指令标识，流水号或者时间
        String modeSeq = split[5].substring(1);//设备的工作模式序号
        String interval = split[6];//主动上传间隔时间
        String deviceTime = split[7];//设备回复的时间
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];
        String deviceStatus = split[16];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        WorkModeReply workModeReply = new WorkModeReply();
        workModeReply.setCommandNumber(commandNumber);
        workModeReply.setDeviceDate(deviceDate);
        workModeReply.setDeviceTime(deviceTime);
        workModeReply.setImei(imei);
        workModeReply.setInterval(Integer.parseInt(interval));
        workModeReply.setModeSeq(Integer.parseInt(modeSeq));
        workModeReply.setDeviceStatus(deviceStatus);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        workModeReply.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_SET_WORK_MODE,false,"",workModeReply);
    }
}
